<?php
require "../common/user_online.php";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>EbookAZ</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<script type="text/javascript" src="../scripts/usermanage_script.js"></script>
	<?php require "../components/head.php" ?>
</head>
<body onload="MakeCurrentPage(1)">
<div id="container">
	<?php require "../components/admin_menu.php" ?>
	<?php require "../components/admin_header.php" ?>
	<div id="content">
		<?php require "../components/content_left.php"?>
		<div id="content_right">
		
			<div id="search">
				<br>
				<tr>						
					<input type="text" id="txtKey" size="30px">
					<input type="button" id="btnSearch" value="Tìm kiếm" onClick="TimKiem()">
				</tr>
				<br>
			</div>
			<hr width="310px" align="left">
			
			<div id="divResult" align="center">
			<?php
			
			//Kết nối csdl
			require "../common/db.inc";
			$conn = new mysqli($host, $username, $password, $dbname);	
			$conn->query("set names 'utf8'");		
			//check connection
			if (mysqli_connect_errno()) {
				printf("Connect failed: %s\n", mysqli_connect_error());
				exit();
			}
			
			$sql = "call sp_CountUser();";
			$result = $conn->query($sql);
			$obj = $result->fetch_object();
			$num_rows = $obj->num_of_users;
		
			
			if(isset ( $_GET["page"] ))
				$page = $_GET["page"];
			else
				$page = 1;
				
			$rows_per_page = 10;
			$pages_per_page = 5;
			$offset = ($page-1)*$rows_per_page;	
			
			
			$conn = new mysqli($host, $username, $password, $dbname);	
			$conn->query("set names 'utf8'");
			if (mysqli_connect_errno()) {
				printf("Connect failed: %s\n", mysqli_connect_error());
				exit();
			}	
	
			$sql = "call sp_GetAllUser($offset, $rows_per_page);";
			$result = $conn->query($sql);
				
			echo "<table width='80%' border='1' cellspacing='0' cellpadding='5px'>";
			echo "<tr style='background-color:#AACCEE' >";
			echo "<th>ID</th>";
			echo "<th>Tài Khoản</th>";
			echo "<th>Email</th>";
			echo "<th>Mana</th>";
			echo "<td>&nbsp; </td>";	
			echo "</tr>";
			
			$i = 0;
			while ($row = $result->fetch_row()) 
			{
				$id	= $row[0];
				$username = $row[1];
				$email = $row[3];
				$mana = $row[5];
				$status = $row[6];
				
				$i = 1 - $i;
				if($i == 0)
					echo "<tr style='background-color:#FFFFE1'>";
				else 
					echo "<tr style='background-color:#E5E5E5'>";
					
				echo "<td style='text-align:center;'>$id</td>";
				echo "<td>$username</td>";		
				echo "<td>$email</td>";		
				echo "<td>$mana</td>";
				
				if($status == 1)
					echo "<td><a href='#' onClick='Active(this, $id); return false;'>Vô hiệu</a></td>";
				else
					echo "<td><a href='#' onClick='Active(this, $id); return false;'>Kích hoạt</a></td>";
				echo "</tr>";
				
			}
			
			echo "</table>";
			include "../common/paging.php";
			$listpage = paging("usermanage.php", $rows_per_page, $pages_per_page, $num_rows, $page, "");
			echo "<br>";
			echo $listpage;
			
			// free result set		
			$result->close();
			$conn->close();			
			?>
			</div>
		</div>
	</div>
	<?php require "../components/footer.php" ?>
</div>
</body>
</html>
